package com.kexio.auth.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import java.io.Serializable;

/**
 * 登录请求DTO
 * 
 * 用户登录时提交的请求参数
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class LoginRequest implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空")
    @Size(min = 2, max = 64, message = "用户名长度必须在2-64个字符之间")
    private String username;
    
    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空")
    @Size(min = 6, max = 32, message = "密码长度必须在6-32个字符之间")
    private String password;
    
    /**
     * 租户ID（多租户场景）
     */
    private String tenantId;
    
    /**
     * 验证码
     */
    private String captcha;
    
    /**
     * 验证码KEY
     */
    private String captchaKey;
    
    /**
     * 登录类型：password-密码登录，sms-短信登录，email-邮箱登录
     */
    private String loginType = "password";
    
    /**
     * 是否记住登录（延长token有效期）
     */
    private Boolean rememberMe = false;
    
    /**
     * 客户端设备信息
     */
    private String deviceInfo;
    
    /**
     * 客户端IP地址（由服务端自动获取，客户端无需传入）
     */
    private String clientIp;
    
    /**
     * User-Agent信息（由服务端自动获取，客户端无需传入）
     */
    private String userAgent;
    
    // ==================== 构造函数 ====================
    
    public LoginRequest() {}
    
    public LoginRequest(String username, String password) {
        this.username = username;
        this.password = password;
    }
    
    public LoginRequest(String username, String password, String tenantId) {
        this(username, password);
        this.tenantId = tenantId;
    }
    
    // ==================== 便捷方法 ====================
    
    /**
     * 判断是否为密码登录
     */
    public boolean isPasswordLogin() {
        return "password".equals(this.loginType);
    }
    
    /**
     * 判断是否为短信登录
     */
    public boolean isSmsLogin() {
        return "sms".equals(this.loginType);
    }
    
    /**
     * 判断是否为邮箱登录
     */
    public boolean isEmailLogin() {
        return "email".equals(this.loginType);
    }
    
    /**
     * 判断是否需要验证码
     */
    public boolean needCaptcha() {
        return captchaKey != null && !captchaKey.trim().isEmpty();
    }
    
    /**
     * 判断是否为多租户登录
     */
    public boolean isMultiTenant() {
        return tenantId != null && !tenantId.trim().isEmpty();
    }
    
    // ==================== Getter/Setter ====================
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getPassword() {
        return password;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
    
    public String getTenantId() {
        return tenantId;
    }
    
    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }
    
    public String getCaptcha() {
        return captcha;
    }
    
    public void setCaptcha(String captcha) {
        this.captcha = captcha;
    }
    
    public String getCaptchaKey() {
        return captchaKey;
    }
    
    public void setCaptchaKey(String captchaKey) {
        this.captchaKey = captchaKey;
    }
    
    public String getLoginType() {
        return loginType;
    }
    
    public void setLoginType(String loginType) {
        this.loginType = loginType;
    }
    
    public Boolean getRememberMe() {
        return rememberMe;
    }
    
    public void setRememberMe(Boolean rememberMe) {
        this.rememberMe = rememberMe;
    }
    
    public String getDeviceInfo() {
        return deviceInfo;
    }
    
    public void setDeviceInfo(String deviceInfo) {
        this.deviceInfo = deviceInfo;
    }
    
    public String getClientIp() {
        return clientIp;
    }
    
    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }
    
    public String getUserAgent() {
        return userAgent;
    }
    
    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }
    
    @Override
    public String toString() {
        return "LoginRequest{" +
                "username='" + username + '\'' +
                ", password='[PROTECTED]'" +
                ", tenantId='" + tenantId + '\'' +
                ", captcha='" + captcha + '\'' +
                ", captchaKey='" + captchaKey + '\'' +
                ", loginType='" + loginType + '\'' +
                ", rememberMe=" + rememberMe +
                ", deviceInfo='" + deviceInfo + '\'' +
                ", clientIp='" + clientIp + '\'' +
                ", userAgent='" + userAgent + '\'' +
                '}';
    }
}
